
/**
 * @File    xxx
 * @brief   xxx
 * @auhtor  xxx
 * @data    xxx
 * @see     xxx
 * @note    xxx
**/

#include "login.h"
#include "msg_proc.h"

// 注册请求
int msg_user_register_ask(struct connect_t *conn)
{
	int retval = 0;
	struct user_register_ask_t ask;

	retval = user_register_ask_unpack(conn->buf_event->input, &ask);
	if(retval == -1) {
		return -1;
	}

	retval = user_register_ask(ask);

	struct proto_head_t proto_head = {PROTO_MAGIC, PROTO_VER, 0, MSG_USER_REGISTER_ANSWER, 0};
	proto_head_pack(conn->ev_buf, &proto_head);

	struct user_register_answer_t answer;
	answer.session = ask.session;
	answer.result = retval;
	answer.id = ask.user_info.id;
	user_register_answer_pack(conn->ev_buf, &answer);

	bufferevent_write_buffer(conn->buf_event, conn->ev_buf);
	evbuffer_drain(conn->ev_buf, evbuffer_get_length(conn->ev_buf));

	return 0;
}

int user_register_ask(struct user_register_ask_t *ask)
{


	return 0;
}

// 注册应答
int msg_user_register_answer(struct connect_t *conn)
{
	struct user_register_answer_t answer;
	user_register_answer_unpack(conn->buf_event->input, &answer);

	return 0;
}

int user_register_answer(struct user_register_answer_t answer)
{

	return 0;
}

// 登录请求
int msg_user_login_ask(struct connect_t *conn)
{
	struct user_login_ask_t ask;
	user_login_ask_unpack(conn->buf_event->input, &ask);

	return 0;
}

int user_login_ask(struct user_login_ask_t ask)
{

	return 0;
}

// 登录应答
int msg_user_login_answer(struct connect_t *conn)
{
	struct user_login_answer_t answer;
	user_login_answer_unpack(conn->buf_event->input, &answer);

	return 0;
}

int user_login_answer(struct user_login_answer_t answer)
{

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int msg_proc(int16_t type, struct connect_t *conn)
{
	switch(type) {
		case MSG_USER_REGISTER_ASK:
			msg_user_register_ask(conn);
			break;
		case MSG_USER_LOGIN_ASK:
			msg_user_login_ask(conn);
			break;
		case MSG_USER_UNREGISTER_ASK:
			msg_user_register_answer(conn);
			break;
		case MSG_USER_LOGOUT_ASK:
			msg_user_login_answer(conn);
			break;
		default:
			break;
	}

	return 0;
}

